import { cloneDeep, isObject } from "lodash-unified";
export const t = () => {};
import SnowflakeId from "snowflake-id";

// export const guid = (num) => {
//   const snowflake = new SnowflakeId({
//     mid: Math.random(),
//   });
//   const arr = [];
//   for (let i = 0; i < num; i++) {
//     arr.push(snowflake.generate());
//   }
//   return num ? arr : snowflake.generate();
// };

export const guid = () => {
  const snowflake = new SnowflakeId({
    mid: Math.floor(Math.random() * 100),
  });
  return snowflake.generate();
};

// 深度合并
export function deepMerge<T = any>(src: any = {}, target: any = {}): T {
  let key: string;
  const res: any = cloneDeep(src);
  for (key in target) {
    res[key] = isObject(res[key])
      ? deepMerge(res[key], target[key])
      : (res[key] = target[key]);
  }
  return res;
}

// 数组对象去重
export function uniqueFunc(arr, uniId = "id") {
  const res = new Map();
  return arr.filter((item) => !res.has(item[uniId]) && res.set(item[uniId], 1));
}
